/* -*- Mode:Prolog; coding:ISO-8859-1; -*- */
:- ensure_loaded([score_tools]).

:- multifile solution_score/1, heuristic_score/4, termination/1, additional_prune/2.
:- discontiguous solution_score/1, heuristic_score/4, termination/1, additional_prune/2.
:- ensure_loaded(['../user/custom_strategies.pl']).
%PROGOL STYLE

solution_score(1) :-
bb_get_value(strategy, progol), !.

heuristic_score(Solution, Evaluation, _Info, HS) :-
bb_get_value(strategy, progol), !,        
        log('--------------------'),
        portray_list(Solution),
        complexity(Solution, S), %print('COMPL '), print(S), nl, nl,
        entailed_negatives(Evaluation, EN),
        entailed_positives(Evaluation, EP),
        HS is -(EP - EN - S),
        log('Score:'), log((HS = -(EP - EN - S))),
        log('--------------------').

termination(_Solution) :-
        bb_get_value(strategy, progol), !, fail.
        
additional_prune(Solution, Evaluation) :-
        bb_get_value(strategy, progol),
        entailed_negatives(Evaluation, EN),
        entailed_positives(Evaluation, EP),
        complexity(Solution, S),
        ET is EN + EP,
        ET = 0,
        HS is -(EP - EN - S),
        HS >0, !, 
        print('Pruned because score '), print(HS), print(' > 0'), print('and zero examples entailed'),
        fail.
    
additional_prune(Solution, Evaluation) :-
        bb_get_value(strategy, progol),
        entailed_positives(Evaluation, EP),
        complexity(Solution, S),
        ET is EP - S,
        ET < 1, !, 
        print('Pruned because complexity higher than positive entailed '), print((EP - S)), print(' > 0'),
        fail.

additional_prune(_Solution, _Evaluation) :-                 
        bb_get_value(strategy, progol), !.



%PROGOL STYLE NO COMPLEXITY

solution_score(1) :-
bb_get_value(strategy, progolnc), !.

heuristic_score(Solution, Evaluation, _Info, HS) :-
bb_get_value(strategy, progolnc), !,        
        log('--------------------'),
        portray_list(Solution),
        entailed_negatives(Evaluation, EN),
        entailed_positives(Evaluation, EP),
        HS is -(EP - EN),
        log('Score:'), log((HS = EP - EN)),
        log('--------------------').

termination(_Solution) :-
        bb_get_value(strategy, progolnc), !, fail.

additional_prune(_S, _Evaluation) :-
        bb_get_value(strategy, progolnc), !.

%BREADTH FIRST
solution_score(1) :-
bb_get_value(strategy, breadth), !.

heuristic_score(Solution, Evaluation, Info, Score) :- %the depth is automatically the next relevant parameter for the score
bb_get_value(strategy, breadth), !,
        check_solution(Solution, Evaluation, Info, Score).
        
termination(Solutions) :-
bb_get_value(strategy, breadth), !,
        terminate_num_sol(Solutions).

additional_prune(_S, _Evaluation) :-
        bb_get_value(strategy, breadth), !.

%%%%
check_solution(Solution, Evaluation, _Info, Score) :-
        log('--------------------'),
        entailed_negatives(Evaluation, EN),
        entailed_positives(Evaluation, EP),
        number_negatives(Evaluation, NN),
        number_positives(Evaluation, NP),
        print('Positive/TotPositive, Negative/TotNegative:'), print((EP/NP, EN/NN)), nl,
        ((EN = 0, NP= EP) ->
                Score = -1
        ;
                Score = 0
        ),
        portray_list(Solution),
        print('score '), print(Score),
        log('--------------------').

terminate_num_sol(Solutions) :-
        length(Solutions, LS),        
        Solutions = [(_, -1) | _],
        bb_get_value(number_of_solutions, NS),
        LS >= NS. 
%%%%%%


%FULLL BREADTH FIRST
solution_score(0) :-
bb_get_value(strategy, full_breadth), !.

heuristic_score(Solution, Evaluation, Info, Score) :- %the depth is automatically the next relevant parameter for the score
bb_get_value(strategy, full_breadth), !,        
        check_solution(Solution, Evaluation, Info, Score).
        
termination(Solutions) :-
bb_get_value(strategy, full_breadth), !,
        terminate_num_sol(Solutions).

additional_prune(_S, _Evaluation) :-
        bb_get_value(strategy, full_breadth), !.